/**
 * 保存行政处罚种类
 * @param data
 * @param callback
 */
function saveAdministrativePunishmentOffLine(data,callback){
	db.transaction(function (tx) {
    	tx.executeSql("INSERT INTO CASE_ADMINISTRATIVE_PUNISHMENT(" +
    			"ADMINISTRATIVEPUNISHMENT_NAME,ORGAN_ID,IS_COMMON,CREATE_TIME) " +
    			"VALUES (?,?,?,?)",
    			[data.administrativePunishmentName==undefined ? '' : data.administrativePunishmentName  ,
				 data.organId==undefined ? '' : data.organId,
				 data.isCommon==undefined ? '' : data.isCommon,
				 data.createTime==undefined ? '' :data.createTime],
       function (tx, result) {
    		closeShade();
    	    if(typeof(callback) == 'function'){
    	    	callback(data);
    	    }
       },
	   function (tx, error) {
    	   closeShade();
    	   message("行政处罚种类保存失败");
	   });
    });
}


/**
 * 清空数据
 */
function caseAdministrativePunishment(callback,data){
	db.transaction(function (tx) { 
		tx.executeSql('DELETE FROM CASE_ADMINISTRATIVE_PUNISHMENT', [], 
		function (tx, results){
			if (typeof(callback) == 'function'){
				$.each(data,function(index,item){
					callback(item);
				});
			}
		}, 
		function (tx, ex){
			message("删除行政处罚种类失败");
		}); 
	});
}




/**
 * 封装数据
 */
function setAdministrativePunishmentDataOffLine(result){
	var len = result.rows.length;
	if(len == 0){
		return null;
	}
    var data = new Array();
	for (var i = 0; i < len; i++){
		var administrativePunishment = {};
		administrativePunishment.id = result.rows.item(i).CASE_ADMINISTRATIVEPUNISHMENT_ID;
		administrativePunishment.administrativePunishmentName = result.rows.item(i).ADMINISTRATIVEPUNISHMENT_NAME;
		administrativePunishment.organId = result.rows.item(i).ORGAN_ID;
		administrativePunishment.isCommon = result.rows.item(i).IS_COMMON;
	    data.push(administrativePunishment);
    }
	return data;
}


/**
 * 通过名称和机构ID查验行政处罚种类是否存在
 * @param administrativePunishmentName,organId
 * @param callback 回调函数
 **/
function findAdministrativePunishmentByNameAndOrganIdOffLine(administrativePunishmentName,administrativePunishmentName,organId,callback){
	db.transaction(function (tx) { 
		tx.executeSql("SELECT * FROM CASE_ADMINISTRATIVE_PUNISHMENT WHERE ADMINISTRATIVEPUNISHMENT_NAME=? and IS_COMMON='是' OR (ADMINISTRATIVEPUNISHMENT_NAME=? AND ORGAN_ID=? AND IS_COMMON='否')", [administrativePunishmentName,administrativePunishmentName,organId], 
		function (tx, result){ 
		    var len = result.rows.length; 
		    if(len > 0){
		    	return;
		    }else{
		    	var time = currentTime();
		    	var administrativePunishment={};
		    	administrativePunishment.administrativePunishmentName=administrativePunishmentName;
		    	administrativePunishment.organId=organId;
		    	administrativePunishment.isCommon='否';
		    	administrativePunishment.createTime=time;
		    	 if(typeof(callback) == 'function'){
		    	    	callback(administrativePunishment);
		    	   }
		    }
	    }, 
	    function(tx, ex) {
        });  
	});
}